<?php

namespace App\Inventor\Controllers;

use App\Extensions\Tools\PatentKeepBatch;
use App\Patent;
use App\Repositories\PatentRepository;
use App\Services\PatentService;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Grid\Tools\Selector;
use Encore\Admin\Show;

class PatentKeepController extends AdminController
{
    public $repository;
    protected $patentService;
    public function __construct(PatentRepository $repository,PatentService $patentService)
    {
        $this->repository = $repository;
        $this->patentService = $patentService;
    }

    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '专利维持';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = $this->repository->userGrid();
        $this->patentService->gridColumn($grid);
        $grid->column('keep_status', __('维持状态'))
            ->using(['放弃维持','继续维持'])->label(['default','success']);
        $grid->disableActions();
        $grid->batchActions(function(Grid\Tools\BatchActions $actions){
            $actions->disableDeleteAndHodeSelectAll();
        });
        $grid->tools(function(Grid\Tools $tools){
            $tools->append(new PatentKeepBatch());
        });
        $grid->selector(function (Selector $selector) {
            $selector->select('keep_status', '维持状态', ['放弃维持','继续维持']);
        });
        $grid->disableFilter();
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Patent::findOrFail($id));

        $show->field('patent_name', __('Patent name'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Patent());
        $form->hidden('keep_status', __('Keep status'));
        return $form;
    }
}
